package com.sxu.demo;

import java.time.LocalTime;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * 任务调度线程池 —— 延迟执行
 */
public class Test7 {
    public static void main(String[] args) {
        ScheduledExecutorService pool = Executors.newScheduledThreadPool(2);

        pool.schedule(()->{
            System.out.println("task 1:" + LocalTime.now().toString());
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        },1, TimeUnit.SECONDS);

        pool.schedule(()->{
            System.out.println("task 2:" + LocalTime.now().toString());
        },1, TimeUnit.SECONDS);
    }
}
